package com.polaris.live.adapter.level

import android.view.View
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterMeRichBinding
import com.polaris.live.resp.back_resp.RichItemVo
import com.polaris.live.ui.me.MeRichFragment

/**
 * 壕气等级规则
 *
 * @author Created by 长空 on 2023/10/21/004 19:36
 */
class MeRichAdapter : BaseBindingAdapter<AdapterMeRichBinding, RichItemVo>() {

    override fun convert(holder: VBViewHolder<AdapterMeRichBinding>, item: RichItemVo) {
        holder.vb.apply {
            levelView.setNormalRichsLevel(item.level)
            tvDiamond.text = item.value.toString()
            item.privilege?.let {
                val msg = if (it.size == 1) {
                    it[0]
                } else {
                    it.mapIndexed { index, s ->
                        "${index + 1}.$s"
                    }.joinToString(separator = "\n")
                }
                tvPrivilege.text = msg
            }

            if (item.value == MeRichFragment.NOSHOW && item.level == MeRichFragment.NOSHOW) {
                hideView(holder)
            } else {
                showView(holder)
            }
        }
    }

    private fun hideView(holder: VBViewHolder<AdapterMeRichBinding>) {
        holder.vb.apply {
            tvDiamond.visibility = View.INVISIBLE
            levelView.visibility = View.INVISIBLE
            lin1.visibility = View.INVISIBLE
            lin2.visibility = View.INVISIBLE
            lin3.visibility = View.INVISIBLE
            lin4.visibility = View.INVISIBLE
            view3.visibility = View.INVISIBLE
        }
    }

    private fun showView(holder: VBViewHolder<AdapterMeRichBinding>) {
        holder.vb.apply {
            tvDiamond.visibility = View.VISIBLE
            levelView.visibility = View.VISIBLE
            lin1.visibility = View.VISIBLE
            lin2.visibility = View.VISIBLE
            lin3.visibility = View.VISIBLE
            lin4.visibility = View.VISIBLE
            view3.visibility = View.VISIBLE
        }
    }

}